package com.android.webttest.model.tableModel;

import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.PrimaryKey;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import lombok.Data;

@Data
@Entity(tableName = "search_history")
public class SearchHistoryRecord {
    @PrimaryKey(autoGenerate = true)
    private Integer id;
    @ColumnInfo(name = "query")
    private String query;
    @ColumnInfo(name = "is_recent")
    private boolean isRecent;     // 是否为最近搜索
    
    @ColumnInfo(name = "search_count")
    private int searchCount;      // 该词被搜索次数

    @ColumnInfo(name = "create_time")
    private String createTime;

    @ColumnInfo(name = "update_time")
    private String updateTime;


    public SearchHistoryRecord(String query) {
        this.query = query;
        this.createTime = getCurrentTime();
        this.updateTime = getCurrentTime();
        this.searchCount = 1;
        this.isRecent = true;
    }

    private static String getCurrentTime() {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()).format(new Date());
    }
}
